home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / map / fixasc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-12  |  1.4 KB  |  78 lines

  1. /*
  2.  *    fixasc.c
  3.  *
  4.  *    Fixes map ascii database redundancies
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. #define    LINESIZE    80
  11.  
  12.  
  13. main(argc, argv)
  14. int    argc;
  15. char    *argv[];
  16. {
  17.     FILE    *fpi, *fpo;
  18.     int    flag, deletions = 0, passes = 0;
  19.     char    line1[80], line2[80];
  20.  
  21.     do  {
  22.        passes++;
  23.        printf("Pass : %d\n", passes);
  24.  
  25.        if ((fpi = fopen(argv[1], "r")) == (FILE *)NULL)  {
  26.            printf("\007Error: Can't locate Database '%s'\n", argv[1]);
  27.            exit(1);
  28.        }
  29.  
  30.        if ((fpo = fopen("tmpdb", "w")) == (FILE *)NULL)  {
  31.            printf("\007Error: Can't create temporary Database\n");
  32.            exit(1);
  33.        }
  34.  
  35.        flag = 0;
  36.  
  37.        for (;;)  {
  38.            if (fgets(line1, LINESIZE, fpi) == NULL)
  39.             break;
  40.  
  41.         if ((line1[0] == '#') || (line1[0] == '\0'))  {
  42.                fputs(line1, fpo);
  43.             continue;
  44.         }
  45.  
  46.         if (fgets(line2, LINESIZE, fpi) == NULL)
  47.             break;
  48.  
  49.         if ((line2[0] == '#') || (line2[0] == '\0'))  {
  50.             fputs(line1, fpo);
  51.                fputs(line2, fpo);
  52.             continue;
  53.         }
  54.  
  55.         if (strcmp(line1, line2) == 0)  {
  56.             fputs(line1, fpo);
  57.             deletions++;
  58.             flag = 1;
  59.         }
  60.         else  {
  61.             fputs(line1, fpo);
  62.             fputs(line2, fpo);
  63.         }
  64.        }
  65.  
  66.        fclose(fpi);
  67.        fclose(fpo);
  68.  
  69.        unlink(argv[1]);
  70.        rename("tmpdb", argv[1]);
  71.     } while (flag == 1);
  72.  
  73.     printf("\nThere were %d deletions in %d passes\n", deletions, passes);
  74.     exit(0);
  75. }
  76.  
  77. /* EOF */
  78.